<template>
	<div class="order-radius">
		<!-- 平台订单列表 -->
		<Table border :columns="columns1" :data="orderList"></Table>
		<!-- 分页 -->
		<br />
		<div style="text-align: center;">
			<Page :total="total" show-sizer show-elevator @on-change="changeUser" />
		</div>
	</div>
</template>

<script>
	import path from '@/api/path.js';
	let url = path.url;
	import axios from '@/libs/api.request';
	export default {
		data() {
			return {
				columns1: [{
						title: '活动编号',
						key: 'id',
						align: 'center'
					},
					{
						title: '活动类型',
						key: 'type',
						align: 'center'
					},
					{
						title: '小区名称',
						key: 'address',
						align: 'center'
					},
					{
						title: '参与时间',
						key: 'createTime',
						align: 'center'
					},
					{
						title: '状态',
						key: 'status',
						align: 'center',
					},
					{
						title: '操作',
						key: 'action',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '10px'
									},
									on: {
										click: (e) => {
											this.delOrder(params.row.id);
										}
									}
								}, '取消订单')
							]);
						}
					}
				],
				orderList: [],
				total: 0,
				page: 1
			};
		},
		methods: {
			// 获取平台订单列表
			getUserOrder() {
				axios.request({
					url: `${url}user/getUserOrderList`,
					method: 'post',
					data: {
						id: this.id,
						page: this.page
					}
				}).then(res => {
					if (res.data.status == 1) {
						this.orderList = res.data.content.data;
						this.orderList.forEach(item=>{
							// item.status == 0 ? '拼团中' : '时间过期'
							if ( item.status == 0 ) {
								item.status = '拼团中'
							} else if ( item.status == 1 ){
								item.status = '时间过期'
							} else {
								item.status = '人数已满'
							}
						})
					} else {
						throw '获取平台订单失败！'
					}
				})
			},
			// 取消订单
			delOrder(id){
				axios.request({
					url: `${url}GroupFound/delGroupFound`,
					method: 'post',
					data: {
						id: id
					}
				}).then(res=>{
					if (res.data.status == 1) {
						this.getUserOrder();
					} else {
						throw '删除订单失败！'
					}
				})
			},
			// 分页跳转
			changeUser(idx) {
				this.page = idx;
				this.getUserInfo();
			}
		},
		created() {
			this.getUserOrder();
		},
		props: ['id']
	}
</script>

<style>

</style>
